import * as actions from '../actions'

const cartsInitialState = {
  products:[],
  count: 0
}

const carts = (state = cartsInitialState, action) => {
  switch (action.type) {
    case actions.ADD_CART:
      state.products.push(action.product)
      return {
        ...state,
        count: state.count + Number(action.product.price)
      }
    case actions.CLEAN_CART:
      return {
        products:[],
        count: 0
      }
    case actions.SET_CART:
      return {
        products: action.products,
        count: 0
      }
    default:
      return state
  }
}

export default carts
